﻿using System;
using System.Text;

namespace CANLib
{
    /// <summary>
    /// This structure holds informations about the connected hardware
    /// </summary>
    public struct HardwareInfo
    {
        private bool mEmpty;

        /// <summary>
        /// Gets if this structure hase alredy been filled with data
        /// </summary>
        public bool IsEmpty
        {
            get
            {
                return mEmpty;
            }
        }
    }

    /// <summary>
    /// Defines the existing types for a message
    /// </summary>
    public enum MessageType
    {
        MSG_UNKNOWN,
        MSG_DATA,
        MSG_INFO,
        MSG_ERROR
    }

    /// <summary>
    /// Defines witch format should be used for byte array converting
    /// </summary>
    public enum ValueFormat
    {
        FMT_UNKNOWN,
        FMT_DOUBLE,
        FMT_INTEGER,
        FMT_STRING
    }


    /// <summary>
    /// Represents a message sent by the hardware
    /// </summary>
    public struct HardwareMessage
    {
        #region ctor

        /// <summary>
        /// Standard constructor used for unknow messages
        /// </summary>
        public HardwareMessage(MessageType type, byte rawMessageType)
        {
            this.mMessageTimeStamp = DateTime.Now;
            this.mMessageType = type;
            this.mMessageText = "Unknown message";
            this.mPacket = null;
            this.mRawMessageType = rawMessageType;
        }

        //----------------------------------------------------------------------------------------

        public HardwareMessage(DateTime stamp, MessageType type, String data)
        {
            this.mMessageTimeStamp = stamp;
            this.mMessageType = type;
            this.mMessageText = data;
            this.mPacket = null;
            this.mRawMessageType = 0;
        }

        //----------------------------------------------------------------------------------------

        public HardwareMessage(DateTime stamp, MessageType type, CANPacket data)
        {
            this.mMessageTimeStamp = stamp;
            this.mMessageType = type;
            this.mMessageText = "Data";
            this.mPacket = data;
            this.mRawMessageType = 0;
        }

        //----------------------------------------------------------------------------------------

        #endregion

        #region Members

        private DateTime mMessageTimeStamp;
        private MessageType mMessageType;
        private byte mRawMessageType;

        private String mMessageText;
        private CANPacket mPacket;

        #endregion

        #region Properties

        /// <summary>
        /// Gets the byte that defines the type of this message
        /// </summary>
        public byte RawMessageType
        {
            get
            {
                return this.mRawMessageType;
            }
        }

        //----------------------------------------------------------------------------------------

        /// <summary>
        /// Gets the type of this message
        /// </summary>
        public MessageType MessageType
        {
            get
            {
                return mMessageType;
            }
        }

        //----------------------------------------------------------------------------------------

        /// <summary>
        /// Gets the time when this message has been received by the hardware
        /// </summary>
        public DateTime TimeStamp
        {
            get
            {
                return mMessageTimeStamp;
            }
        }

        //----------------------------------------------------------------------------------------

        /// <summary>
        /// Gets the text of the message
        /// </summary>
        public String MessageText
        {
            get
            {
                return this.mMessageText;
            }
        }

        //----------------------------------------------------------------------------------------

        /// <summary>
        /// Gets the CAN-Packet from this message (only available when MessageType is MSG_DATA)
        /// </summary>
        public CANPacket Data
        {
            get
            {
                return this.mPacket;
            }
        }

        //----------------------------------------------------------------------------------------

        #endregion

        #region Methods

        

        #endregion

    }
}